package cn.qiao.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * desc:
 *
 * @author qiao
 * @date 2023年07月19日 22:07
 */
public class LogHandlerProxy  implements InvocationHandler {

    private Object target;

    public LogHandlerProxy(Object target) {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {



        System.out.println("方法执行开始前时间："+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));

        Object invoke = method.invoke(target, args);

        System.out.println("方法执行完成后时间："+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        return invoke;

    }
}
